create PROCEDURE 报表名称 @begingmt_create DATETIME,
                          @endgmt_create DATETIME,
                          @PageIndex INT,
                          @PageSize INT,
                          @TotalCount INT OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    -- 计算分页的起始位置
    DECLARE @Offset INT = (@PageIndex - 1) * @PageSize;
--------------------------------------------------------------------------------------------
    select *
    from mes_batch_order a

------------------------------------------------------------------------------------------------------


    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)


    order by a.gmt_create desc
    OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY;

    SELECT @TotalCount = COUNT(1)

    ---------------------------------------------------------------------

    from mes_batch_order a
    -------------------------------------------

    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)

END